#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

pair<int, int> dir[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> maze(n);
  for (auto &x : maze) cin >> x;
  auto in_maze = [&](int x, int y) -> bool {
    return x >= 0 && x < n && y >= 0 && y < m;
  };
  queue<pair<int, int>> q;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      if (maze[i][j] == '#') {
        for (auto [dx, dy] : dir) {
          int nx = i + dx, ny = j + dy;
          if (in_maze(nx, ny) && maze[nx][ny] == '.') {
            q.emplace(nx, ny);
          }
        }
      }
    }
  }
  while (!q.empty()) {
    int sz = q.size();
    vector<pair<int, int>> cand;
    while (sz --) {
      auto [x, y] = q.front();
      q.pop();
      int cnt = 0;
      for (auto [dx, dy] : dir) {
        int nx = x + dx, ny = y + dy;
        if (in_maze(nx, ny) && maze[nx][ny] == '#') cnt ++;
      }
      if (cnt == 1) cand.emplace_back(x, y);
    }
    for (auto [x, y] : cand) {
      maze[x][y] = '#';
      for (auto [dx, dy] : dir) {
        int nx = x + dx, ny = y + dy;
        if (in_maze(nx, ny) && maze[nx][ny] == '.') {
          q.emplace(nx, ny);
        }
      }
    }
  }
  int ans = 0;
  for (auto &row : maze) ans += count(row.begin(), row.end(), '#');
  cout << ans << endl;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  for (int cas = 1; cas <= T; cas ++) {
    solve();
  }
}